<html>
<head><meta charset="utf-8"><title>why-is-this-ok-with-nll · t-compiler/wg-nll · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/index.html">t-compiler/wg-nll</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html">why-is-this-ok-with-nll</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="133809802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133809802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133809802">(Sep 12 2018 at 16:20)</a>:</h4>
<p>Why does this compile with NLL?</p>
<div class="codehilite"><pre><span></span><span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">collections</span>::<span class="n">HashSet</span><span class="p">;</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">h</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">HashSet</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">h</span><span class="p">.</span><span class="n">insert</span><span class="p">((</span><span class="o">&amp;</span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">b</span><span class="p">));</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="133809882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133809882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133809882">(Sep 12 2018 at 16:21)</a>:</h4>
<p>why wouldn't it?</p>



<a name="133809949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133809949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133809949">(Sep 12 2018 at 16:22)</a>:</h4>
<p>I guess you are imagining: there is a drop on <code>HashSet</code>, and it has access to those (invalid) references?</p>



<a name="133809951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133809951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133809951">(Sep 12 2018 at 16:22)</a>:</h4>
<p>yep</p>



<a name="133809961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133809961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133809961">(Sep 12 2018 at 16:22)</a>:</h4>
<p>this is because <code>HashSet</code> declares that it doesn't touch the K, V pairs during drop</p>



<a name="133809971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133809971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133809971">(Sep 12 2018 at 16:22)</a>:</h4>
<p>does hashset have the... yeah</p>



<a name="133809972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133809972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133809972">(Sep 12 2018 at 16:22)</a>:</h4>
<p>via its <code>#[may_dangle]</code> attribute</p>



<a name="133810006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133810006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133810006">(Sep 12 2018 at 16:23)</a>:</h4>
<p>I guess the flip question is then... why doesn't it work without NLL?</p>



<a name="133810042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133810042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133810042">(Sep 12 2018 at 16:23)</a>:</h4>
<p>Is NLL aware of <code>may_dangle</code>?</p>



<a name="133810140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133810140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133810140">(Sep 12 2018 at 16:24)</a>:</h4>
<p>NLL is aware of <code>#[may_dangle]</code>, yes</p>



<a name="133810144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133810144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133810144">(Sep 12 2018 at 16:24)</a>:</h4>
<p>as is the AST borrowck</p>



<a name="133810166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133810166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133810166">(Sep 12 2018 at 16:25)</a>:</h4>
<p>the reason that it didn't work with the old borrowck is that there is a fundamental rule that the type of each variable must be live until the end of the block</p>



<a name="133810179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133810179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133810179">(Sep 12 2018 at 16:25)</a>:</h4>
<p>or, sort of, right up until it is dropped (but not necessarily during the call to drop itself)</p>



<a name="133810186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133810186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133810186">(Sep 12 2018 at 16:25)</a>:</h4>
<p>(that is where may-dangle comes in)</p>



<a name="133810235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133810235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133810235">(Sep 12 2018 at 16:26)</a>:</h4>
<p>in AST borrowck, when would <code>may_dangle</code> have an effect?</p>



<a name="133810236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133810236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133810236">(Sep 12 2018 at 16:26)</a>:</h4>
<p>so, in this case, the <code>h</code> type has to be live until it is dropped, but that outlives <code>a</code></p>



<a name="133810247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133810247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133810247">(Sep 12 2018 at 16:26)</a>:</h4>
<p>you can observe it if you build up cycles</p>



<a name="133810251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133810251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133810251">(Sep 12 2018 at 16:26)</a>:</h4>
<p>it's rather awkward to do, but it happens</p>



<a name="133810256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133810256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133810256">(Sep 12 2018 at 16:26)</a>:</h4>
<p>arenas are a case of this:</p>



<a name="133810276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133810276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133810276">(Sep 12 2018 at 16:26)</a>:</h4>
<p>when you allocate from an arena, you get something that lives with its lifetime, and you can build up cycles amongst those data structures</p>



<a name="133810890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133810890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133810890">(Sep 12 2018 at 16:36)</a>:</h4>
<p>Do you think that with the spread of NLL, <code>may_dangle</code> may gain more prominence? Since it will be more obvious that code in this general shape can work for <code>Vec</code> but not for <code>MyCustomContainer</code>?</p>
<p>I guess if it's built on top of one of the stdlib containers you can benefit...</p>



<a name="133810934"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133810934" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133810934">(Sep 12 2018 at 16:36)</a>:</h4>
<p>thus pushing to stabilize it in some fashion</p>



<a name="133811002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811002">(Sep 12 2018 at 16:37)</a>:</h4>
<p>hmm</p>



<a name="133811004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811004">(Sep 12 2018 at 16:38)</a>:</h4>
<p>I hadn't thought about that</p>



<a name="133811046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811046">(Sep 12 2018 at 16:38)</a>:</h4>
<p>perhaps</p>



<a name="133811056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811056">(Sep 12 2018 at 16:38)</a>:</h4>
<p>I would like to get our story straight</p>



<a name="133811060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811060">(Sep 12 2018 at 16:38)</a>:</h4>
<p>there are also some details of how it integrates with NLL that need a bit of work</p>



<a name="133811218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811218">(Sep 12 2018 at 16:40)</a>:</h4>
<p>Is "values in a scope are dropped in the opposite order they are created" no longer strictly true? Is <code>h</code> dropped before <code>a</code>? Or is there actually some dangly going on?</p>



<a name="133811264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811264">(Sep 12 2018 at 16:41)</a>:</h4>
<p>it is strictly true</p>



<a name="133811319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811319">(Sep 12 2018 at 16:42)</a>:</h4>
<p>but we only require data to be live where it is used now</p>



<a name="133811322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811322">(Sep 12 2018 at 16:42)</a>:</h4>
<p>and we know the drop of <code>h</code> doesn't use <code>a</code></p>



<a name="133811368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811368">(Sep 12 2018 at 16:43)</a>:</h4>
<p>which is via the <code>#[may_dangle]</code></p>



<a name="133811388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811388">(Sep 12 2018 at 16:43)</a>:</h4>
<p>yes</p>



<a name="133811434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811434">(Sep 12 2018 at 16:44)</a>:</h4>
<p>I can see why you might want to have a more general "I guarantee this function won't access this value" then, and why it would be very difficult to get that right</p>



<a name="133811473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811473">(Sep 12 2018 at 16:45)</a>:</h4>
<p>I think that <span class="user-mention" data-user-id="120791">@RalfJ</span>'s approach feels pretty right, but we've not tried to work it out too hard</p>



<a name="133811481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811481">(Sep 12 2018 at 16:45)</a>:</h4>
<p>basically being able to say that, in contrast to a regular function, this type need not be valid in this function</p>



<a name="133811488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811488">(Sep 12 2018 at 16:45)</a>:</h4>
<p>this will in turn have to propagate to helper functions and the like</p>



<a name="133811533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811533">(Sep 12 2018 at 16:46)</a>:</h4>
<p>there is basically an implicit outlives clause in all functions now that says</p>



<a name="133811545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811545">(Sep 12 2018 at 16:46)</a>:</h4>
<p>for each type parameter T, the value given for T must outlive the call to the fn itself</p>



<a name="133811548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811548">(Sep 12 2018 at 16:46)</a>:</h4>
<p>this would be sort of removing that... but it has trickle-down effects</p>



<a name="133811565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811565">(Sep 12 2018 at 16:47)</a>:</h4>
<p>e.g., right now, <code>drop</code> has the signature <code>&amp;mut self</code> -- but normally we require that <code>&amp;'a mut Self</code> is valid if <code>Self: 'a</code></p>



<a name="133811576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811576">(Sep 12 2018 at 16:47)</a>:</h4>
<p>and here we are saying that the <code>self</code> is valid (so <code>'a</code> is live) but some of the data in <code>Self</code> is not...?</p>



<a name="133811579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811579">(Sep 12 2018 at 16:47)</a>:</h4>
<p>not sure how to deal with that</p>



<a name="133811583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Keith Yeung <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811583">(Sep 12 2018 at 16:47)</a>:</h4>
<p>huh, so that means temporaries created just for the purpose of being an argument to a function call already outlives the call itself nowadays?</p>



<a name="133811749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811749">(Sep 12 2018 at 16:50)</a>:</h4>
<p>yes</p>



<a name="133811753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811753">(Sep 12 2018 at 16:50)</a>:</h4>
<p>(of course?)</p>



<a name="133811766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811766">(Sep 12 2018 at 16:50)</a>:</h4>
<p><a href="https://stackoverflow.com/questions/47662253/why-is-it-legal-to-borrow-a-temporary" target="_blank" title="https://stackoverflow.com/questions/47662253/why-is-it-legal-to-borrow-a-temporary">https://stackoverflow.com/questions/47662253/why-is-it-legal-to-borrow-a-temporary</a></p>



<a name="133811777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Keith Yeung <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811777">(Sep 12 2018 at 16:51)</a>:</h4>
<p>because lexically it looks as if it only lives during the function call, not outlive it</p>



<a name="133811792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811792">(Sep 12 2018 at 16:51)</a>:</h4>
<p>conceptually, it outlives the call by like one line</p>



<a name="133811864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll/near/133811864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/why-is-this-ok-with-nll.html#133811864">(Sep 12 2018 at 16:52)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="n">foo</span><span class="p">(</span><span class="o">&amp;</span><span class="nb">String</span>::<span class="n">new</span><span class="p">());</span><span class="w"></span>
</pre></div>


<div class="codehilite"><pre><span></span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">__a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">String</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">foo</span><span class="p">(</span><span class="o">&amp;</span><span class="n">__a</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>